<?php
include("utils.php");
main_content("main();");
function main()
{
if($_REQUEST['mode'] == 'user_purchase_history')
{
	$SQL_purchase_history="select * from ".ORDER_MASTER." as OM, ".ORDER_DETAILS." as OD where OM.siteuserId = '".$_SESSION['siteuserId']."' and OM.order_id = OD.order_id and OD.siteuserId = '".$_SESSION['siteuserId']."' and OM.order_date >= '".$_REQUEST['start_date']."' and OM.order_date <= '".$_REQUEST['end_date']."'";
//echo $SQL_purchase_history;
}
else
{
$SQL_purchase_history="select * from ".ORDER_MASTER." as OM, ".ORDER_DETAILS." as OD where OM.siteuserId = '".$_SESSION['siteuserId']."' and OM.order_id = OD.order_id and OD.siteuserId = '".$_SESSION['siteuserId']."'";
}
$EXE_purchase_history=mysql_query($SQL_purchase_history);

// echo $SQL_purchase_history;
?>
<script language="javascript" type="text/javascript" src="JavaScripts/datetimepicker.js"></script>

<script language="JavaScript">
function user_purchase_history1()
{
	document.user_purchase_history.mode.value='user_purchase_history';
	document.user_purchase_history.submit();
}
</script>

<form name="user_purchase_history" action="" method="POST" id="user_purchase_history">
<input type="hidden" name="mode" value="">
<table width="80%" class="center" cellspacing="0" cellpadding="0">
		  <tr>
			<td align="right"><img src="images/red_table_ltop.jpg" alt="" /></td>
			<td class="red_table_top"></td>
			<td><img src="images/red_table_rtop.jpg" alt="" /></td>
		  </tr>
		  <tr>
			<td class="red_table_LSide" style="background-position:right;"></td>
			
			
			<!-- ban body part -->
			<td class="inner_contentArea" align="center">
			<table width="750" cellspacing="0" cellpadding="0" border="0">
			<tr>
				<td align="center" class="sky font-18">Ad Purchases</td>
			</tr>
			<tr>
				<td align="center" class="sky font-18">&nbsp;</td>
			</tr>
			<tr>
				<td align="center">
  				<form id="dateFilter" name="calendarform" action="" method="post" style="margin: 30px;">

					<table>
						<tr>
							<td class="top_navLink">Show starts :</td>
							<td> 
								<input type="text" name="start_date" id="start_date" value="<?php echo $previousyear; ?>" class="InputBox" onClick="javascript:NewCal('start_date','yyyymmdd',false,24);" style="width:100;" maxlength="100" >&nbsp;to:&nbsp; 
	<input type="text" name="end_date" id="end_date" value="<?php echo $nextyear; ?>" class="InputBox" onClick="javascript:NewCal('end_date','yyyymmdd',false,24);" style="width:100" maxlength="100">
							&nbsp;&nbsp;&nbsp;
							<input type="button" name="Submit1" value="Run" onclick="user_purchase_history1()"/>
							</td>
						</tr>
					</table>
				</form>
				</td>
			</tr>
			<tr>
				<td align="center" id="errorId">&nbsp;</td>
			</tr>
			<tr>
				<td align="center" id="errorId">&nbsp;</td>
			</tr>
			<tr>
			
			<tr>
				<td>
				<table width="750" class="mainTable" cellspacing="0" cellpadding="0">
		
				<tr>
					<td class="sitename"><a href="#" class="headerLink">Date</a></td>
					<td class="product"><a href="#" class="headerLink">PaymentId</a></td>
					<td class="rank"><a href="#" class="headerLink">Website</a></td>
					<td class="impression"><a href="#" class="headerLink">Ad Name</a></td>
					<td class="impression"><a href="#" class="headerLink">Amount</a>&nbsp;</td>
					<td class="cpc"><a href="#" class="headerLink">Units</a></td>
					<td class="price"><a href="#" class="headerLink">Price</a></td>
				</tr>

				<?php
				if(mysql_num_rows($EXE_purchase_history)>0)
				{
					while($ROW_purchase_history=mysql_fetch_array($EXE_purchase_history))
					{
					$SQL_select_siteName="select adSiteName from ".SITEMASTER." where adsiteId = '".$ROW_purchase_history['adsiteId']."'";
					$EXE_select_siteName=mysql_query($SQL_select_siteName);
					$ROW_select_siteName=mysql_fetch_array($EXE_select_siteName);
			
					$site_name=$ROW_select_siteName['adSiteName'];

					$SQL_select_advertiseName="select adTitle from ".ADVERTISEMASTER." where advertiseId = '".$ROW_purchase_history['advertiseId']."'";
					$EXE_select_advertiseName=mysql_query($SQL_select_advertiseName);
					$ROW_select_advertiseName=mysql_fetch_array($EXE_select_advertiseName);

					$advertise_name=$ROW_select_advertiseName['adTitle'];
					
				?>
				<tr>
					<td class="<?php echo $class4;?>" align="center"><?php echo $ROW_purchase_history['order_date']; ?></td>
					<td class="<?php echo $class4;?>" align="center"><?php echo $ROW_purchase_history['paymentId']; ?></td>
					<td class="<?php echo $class4;?>" align="center"><?php echo $site_name; ?></td>
					<td class="<?php echo $class4;?>" align="center"><?php echo $advertise_name; ?></td>
					<td class="<?php echo $class4;?>" align="center"><?php echo $ROW_purchase_history['grand_total']; ?></td>
					<td class="<?php echo $class4;?>" align="center">1</td>
					<td class="<?php echo $class4;?>" align="center"><?php echo $ROW_purchase_history['adspace_price']; ?></td>
				</tr>
				<?php
					}
				}
				?>
				</table>
				</td>
			</tr>
			</table>
			</td>
			<!-- /ban body part -->			
			
			
			<td class="red_table_RSide"></td>
		  </tr>
		  <tr>
			<td align="right"><img src="images/red_table_lbottom.jpg" alt="" /></td>
			<td class="red_table_bottom"></td>
			<td><img src="images/red_table_rbottom.jpg" alt="" /></td>
		  </tr>
		</table>
</form>
<?php
}
?>
